package com.learnyou.server.xingzuo;

import cn.hutool.core.convert.ConverterRegistry;
import cn.hutool.extra.spring.EnableSpringUtil;
import com.learnyou.server.xingzuo.biz.IBehaviorParser;
import com.learnyou.server.xingzuo.common.converter.MyStringConverter;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import springfox.documentation.oas.annotations.EnableOpenApi;

import javax.annotation.Resource;

@SpringBootApplication

@EnableFeignClients(basePackages = {"com.learnyou.server.xingzuo.biz.client"})
@MapperScan("com.learnyou.server.xingzuo.dao.repository.mapper")
@EnableSpringUtil
@EnableOpenApi
@EnableCaching
@EnableScheduling
@EnableAsync
public class XingzuoWebserverApplication implements CommandLineRunner {

	@Bean(name="msgExecutor")
	public TaskExecutor taskExecutor() {
		ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
		taskExecutor.setCorePoolSize(3);
		taskExecutor.setMaxPoolSize(3);
		taskExecutor.setQueueCapacity(100);
		taskExecutor.afterPropertiesSet();
		return taskExecutor;
	}

	public static void main(String[] args) {

		/**
		 * 自定义类型转换，转换数组为逗号分隔字符串
		 */
		ConverterRegistry converterRegistry = ConverterRegistry.getInstance();
		converterRegistry.putCustom(String.class, new MyStringConverter());
		SpringApplication.run(XingzuoWebserverApplication.class, args);
	}

	@Resource
	private IBehaviorParser behaviorParser;

	@Override
	public void run(String... args) throws Exception {
//		behaviorParser.process();
	}
}
